package cn.fl.finance.service.impl;

import java.util.List;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cn.fl.finance.api.IFinLoanDtlApiService;
import cn.fl.finance.condition.FinLoanDtlQC;
import cn.fl.finance.constant.FinLoanConstant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fl.finance.dto.FinLoanDtlDTO;
import cn.fl.finance.service.IFinLoanDtlService;
import cn.fl.finance.transform.FinLoanDtlVOTransform;
import cn.fl.finance.vo.FinLoanDtlVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;

/**
 * @Description: 借款明细表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class FinLoanDtlServiceImpl implements IFinLoanDtlService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IFinLoanDtlService.class);
	
	@Autowired
	private IFinLoanDtlApiService finLoanDtlApiService;
	@Autowired
	private ISysDictionaryApiService dictionaryApiService;

	@Override
	public FinLoanDtlVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		FinLoanDtlDTO dto = finLoanDtlApiService.getById(id);//this.自定义ApiService.selectById(id);
		FinLoanDtlVO dtlVO = FinLoanDtlVOTransform.toVO(dto);
		// 字典转换
		// 借款类型
		SysDictionaryDTO code = dictionaryApiService.getCode(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), FinLoanConstant.FIN_LOAN_TYP_DIDC, dtlVO.getLoanTypCd());
		dtlVO.setLoanTypCdNm(code.getCodeNm());
		return dtlVO;
	}

	@Override
	public Long add(FinLoanDtlVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.finLoanDtlApiService.add(FinLoanDtlVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.finLoanDtlApiService.removeById(id);
		//TODO 业务逻辑
		return false;
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(FinLoanDtlVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		//return this.finLoanDtlApiService.modify(FinLoanDtlVOTransform.toDTO(entity));
		//TODO 业务逻辑
		return false;
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		//return this.finLoanDtlApiService.searchListPage(page);
		//TODO 业务逻辑
		return null;
	}

	@Override
	public List<FinLoanDtlVO> selectList(FinLoanDtlQC qc) {
		List<FinLoanDtlDTO> dtoList = finLoanDtlApiService.selectList(qc);
		return FinLoanDtlVOTransform.toVOList(dtoList);
	}

	@Override
	public void deleteByLoanInfoId(Long loanInfoId) {
		this.finLoanDtlApiService.deleteByLoanInfoId(loanInfoId);
	}
}
